﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ToolPositioningInternal.CUiTPIGraphicControlHelper
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.Drawing;
using Tecnomatix.Engineering;
using UiInternalControls.WPF;


namespace DnProcessSimulateCommands.ToolPositioningInternal;

public static class CUiTPIGraphicControlHelper
{
  private const int _graphicControlWidth = 340;
  private const int _graphicControlHeight = 340;

  public static int Width => 340;

  public static int Height => 340;

  public static void AdjustCameraPosition(this TxGraphicControl gv, TxVector pos, bool dorefresh = true)
  {
    gv.ReferencePoint = new TxVector();
    gv.CameraPosition = pos;
    gv.ZoomToFit();
    gv.Zoom(0.94);
    if (!dorefresh)
      return;
    gv.Refresh();
  }

  public static GraphicControlPreviewState KeepState(this TxGraphicControl gv)
  {
    double num1 = 0.0;
    double num2;
    gv.GetCameraOrientation(ref num2, ref num1);
    return new GraphicControlPreviewState()
    {
      ReferencePoint = gv.ReferencePoint,
      CameraPosition = gv.CameraPosition,
      Theta = num2,
      Phi = num1,
      ViewRect = gv.ViewRect
    };
  }

  public static void RestoreState(this TxGraphicControl gv, GraphicControlPreviewState state)
  {
    if (state == null)
      return;
    gv.CameraPosition = state.CameraPosition;
    gv.ReferencePoint = state.ReferencePoint;
    gv.SetCameraOrientation(state.Theta, state.Phi);
    if (state.ViewRect != RectangleF.Empty)
    {
      gv.ViewRect = state.ViewRect;
    }
    else
    {
      gv.ZoomToFit();
      gv.Zoom(0.94);
    }
    gv.Refresh();
  }

  public static TxColor PickRandomColor()
  {
    Random random = new Random();
    return new TxColor((byte) random.Next(0, 254), (byte) random.Next(0, 254), (byte) random.Next(0, 254));
  }

  public static TxColor PreviewColor()
  {
    return new TxColor((byte) 128 /*0x80*/, (byte) 128 /*0x80*/, (byte) 128 /*0x80*/);
  }
}
